<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"vchao.top","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="之前打算写这一整个系列，但是技术有限，怕写出来错误太多误人子弟。就一直拖着没做。今年疫情嚣张，倒也抽出了时间整理下这部分。权当抛砖引玉之用，如有错误，还望不吝赐教。中国加油！武汉加油！希望疫情早日过去。  前言登录注册应该是安卓开发中最基础也最通用的功能了。本文就通过这部分来带领大家熟悉一下Bmob的使用。 本人能力有限，很多地方也描述不清。大家可自行查看Bmob开发文档。（http:&#x2F;&#x2F;doc">
<meta property="og:type" content="article">
<meta property="og:title" content="手把手带你撸一个校园APP（三）：用户模块（登录注册等）">
<meta property="og:url" content="http://vchao.top/2018/04/12/%E6%89%8B%E6%8A%8A%E6%89%8B%E5%B8%A6%E4%BD%A0%E6%92%B8%E4%B8%80%E4%B8%AA%E6%A0%A1%E5%9B%ADAPP%EF%BC%88%E4%B8%89%EF%BC%89%EF%BC%9A%E7%94%A8%E6%88%B7%E6%A8%A1%E5%9D%97%EF%BC%88%E7%99%BB%E5%BD%95%E6%B3%A8%E5%86%8C%E7%AD%89%EF%BC%89/index.html">
<meta property="og:site_name" content="乘风破浪">
<meta property="og:description" content="之前打算写这一整个系列，但是技术有限，怕写出来错误太多误人子弟。就一直拖着没做。今年疫情嚣张，倒也抽出了时间整理下这部分。权当抛砖引玉之用，如有错误，还望不吝赐教。中国加油！武汉加油！希望疫情早日过去。  前言登录注册应该是安卓开发中最基础也最通用的功能了。本文就通过这部分来带领大家熟悉一下Bmob的使用。 本人能力有限，很多地方也描述不清。大家可自行查看Bmob开发文档。（http:&#x2F;&#x2F;doc">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2018-04-12T09:51:40.000Z">
<meta property="article:modified_time" content="2021-08-25T14:37:20.808Z">
<meta property="article:author" content="vchao">
<meta property="article:tag" content="Android">
<meta property="article:tag" content="科师有约">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://vchao.top/2018/04/12/%E6%89%8B%E6%8A%8A%E6%89%8B%E5%B8%A6%E4%BD%A0%E6%92%B8%E4%B8%80%E4%B8%AA%E6%A0%A1%E5%9B%ADAPP%EF%BC%88%E4%B8%89%EF%BC%89%EF%BC%9A%E7%94%A8%E6%88%B7%E6%A8%A1%E5%9D%97%EF%BC%88%E7%99%BB%E5%BD%95%E6%B3%A8%E5%86%8C%E7%AD%89%EF%BC%89/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>手把手带你撸一个校园APP（三）：用户模块（登录注册等） | 乘风破浪</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">乘风破浪</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://vchao.top/2018/04/12/%E6%89%8B%E6%8A%8A%E6%89%8B%E5%B8%A6%E4%BD%A0%E6%92%B8%E4%B8%80%E4%B8%AA%E6%A0%A1%E5%9B%ADAPP%EF%BC%88%E4%B8%89%EF%BC%89%EF%BC%9A%E7%94%A8%E6%88%B7%E6%A8%A1%E5%9D%97%EF%BC%88%E7%99%BB%E5%BD%95%E6%B3%A8%E5%86%8C%E7%AD%89%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="vchao">
      <meta itemprop="description" content="怀揣好奇，梦想改变世界的菜鸟极客">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="乘风破浪">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          手把手带你撸一个校园APP（三）：用户模块（登录注册等）
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-04-12 17:51:40" itemprop="dateCreated datePublished" datetime="2018-04-12T17:51:40+08:00">2018-04-12</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-08-25 22:37:20" itemprop="dateModified" datetime="2021-08-25T22:37:20+08:00">2021-08-25</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <blockquote>
<p>之前打算写这一整个系列，但是技术有限，怕写出来错误太多误人子弟。就一直拖着没做。今年疫情嚣张，倒也抽出了时间整理下这部分。权当抛砖引玉之用，如有错误，还望不吝赐教。<br>中国加油！武汉加油！希望疫情早日过去。</p>
</blockquote>
<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>登录注册应该是安卓开发中最基础也最通用的功能了。本文就通过这部分来带领大家熟悉一下Bmob的使用。</p>
<p>本人能力有限，很多地方也描述不清。大家可自行查看Bmob开发文档。（<a target="_blank" rel="noopener" href="http://doc.bmob.cn/data/android/develop_doc/%EF%BC%89">http://doc.bmob.cn/data/android/develop_doc/）</a></p>
<p><a target="_blank" rel="noopener" href="https://vchao.blog.csdn.net/article/details/80787263">手把手带你撸一个校园APP（一）：项目简介</a><br><a target="_blank" rel="noopener" href="https://vchao.blog.csdn.net/article/details/81456617">手把手带你撸一个校园APP（二）：应用启动和欢迎页面</a></p>
<h2 id="后台"><a href="#后台" class="headerlink" title="后台"></a>后台</h2><p>为了更加高效的开发，校园APP并没有自己编写后台代码，而是采用的Bmob后端云提供的数据库功能。其实如果想自己写后台的话也可以，原理大致相同。</p>
<h2 id="数据库设计"><a href="#数据库设计" class="headerlink" title="数据库设计"></a>数据库设计</h2><p>因为我们要用的是Bmob提供的云数据库，所以就得先了解下bmob数据库的规则。</p>
<blockquote>
<p>与其它数据库不同，Bmob在数据存储与数据类型方面都有一套自己的规范。从数据存储方面来说，所有存储数据均会默认增加唯一标识objectId，创建时间createdAt等常用属性，在设计数据格式时，无需再重复这些属性。从数据类型方面来说，Bmob支持的数据类型更为广泛，除了String、Float、Boolean等基础类型之外，同时也支持日期格式类型BmobDate和文件格式类型BmobFile等特有的数据类型。</p>
</blockquote>
<p>总结一下就是：</p>
<ul>
<li>默认增加objectId,createdAt,updateAt 等字段（每个表的主键，还有创建时间等无需额外处理了）</li>
<li>支持文件存储（一些图片可以直接存起来）</li>
</ul>
<p>回到我们的需求，整理一下，不难发现用户信息表需要以下字段：</p>
<table>
<thead>
<tr>
<th>字段名</th>
<th>描述</th>
<th>类型</th>
<th>主键</th>
</tr>
</thead>
<tbody><tr>
<td>objectId</td>
<td>用户id</td>
<td>String</td>
<td>是</td>
</tr>
<tr>
<td>username</td>
<td>用户名</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>password</td>
<td>密码</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>mobilePhoneNumber</td>
<td>手机号</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>clazz</td>
<td>班级</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>sex</td>
<td>性别</td>
<td>Boolean</td>
<td></td>
</tr>
<tr>
<td>stuno</td>
<td>学号</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>yuan</td>
<td>院系</td>
<td>String</td>
<td></td>
</tr>
</tbody></table>
<p>更贴心的是，Bmob中提供了默认的User表。上面的很多字段已经包含在内了。直接在控制台_User 表中补充其它字段即可。</p>
<h2 id="安卓端程序"><a href="#安卓端程序" class="headerlink" title="安卓端程序"></a>安卓端程序</h2><h2 id="布局"><a href="#布局" class="headerlink" title="布局"></a>布局</h2><p>页面布局比较简单，有点基础的基本都可以看出来，这里遵循Material Design风格，控件使用了 TextInputLayout 。</p>
<h3 id="TextInputLayout"><a href="#TextInputLayout" class="headerlink" title="TextInputLayout"></a>TextInputLayout</h3><p>TextInputLayout 主要是作为 EditText 的容器，从而为 EditText 生成一个浮动的 Label，当用户点击 EditText 的时候，EditText 中的 hint 字符串会自动移到 EditText 的左上角。</p>
<p><strong>为什么使用TextInputLayout</strong> </p>
<ol>
<li>方便控制密码输入框内容的显示与隐藏</li>
<li>浮动提示语（Metrial Design风格）</li>
</ol>
<p>当然了，不使用也没有什么影响。</p>
<p><strong>基本用法：</strong><br>xml布局</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">android.support.design.widget.TextInputLayout</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">EditText</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">android.support.design.widget.TextInputLayout</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p><strong>扩展：TextInputLayout 常用属性及方法：</strong></p>
<table>
<thead>
<tr>
<th>属性名</th>
<th>对应方法</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>app:hint</td>
<td>setHint(CharSequence)</td>
<td>设置浮动提示语</td>
</tr>
<tr>
<td>app:hintEnabled</td>
<td>setHintEnabled(boolean)</td>
<td>设置是否开启浮动功能</td>
</tr>
<tr>
<td>app:hintAnimationEnabled</td>
<td>setHintAnimationEnabled(boolean)</td>
<td>设置是否开启浮动提示动画</td>
</tr>
<tr>
<td>null</td>
<td>setError</td>
<td>设置错误提示</td>
</tr>
<tr>
<td>app:errorEnabled</td>
<td>setErrorEnabled(boolean)</td>
<td>设置是否开启错误提示</td>
</tr>
<tr>
<td>app:counterEnabled</td>
<td>setCounterEnabled(boolean)</td>
<td>设置是否开启计数器</td>
</tr>
<tr>
<td>app:counterMaxLength</td>
<td>setCounterMaxLength(int)</td>
<td>设置计数器的最大长度（超过并不影响输入）</td>
</tr>
<tr>
<td>app:passwordToggleEnabled</td>
<td>setPasswordVisibilityToggleEnabled(boolean)</td>
<td>设置是否开启密码可见开关(EditText必须为password类型才起作用)</td>
</tr>
<tr>
<td>app:passwordToggleDrawable</td>
<td>setPasswordVisibilityToggleDrawable(Drawable)</td>
<td>设置密码可见开关的图标</td>
</tr>
</tbody></table>
<h2 id="java-逻辑"><a href="#java-逻辑" class="headerlink" title="java 逻辑"></a>java 逻辑</h2><p>该部分基本按照bmob官方文档来操作。<a target="_blank" rel="noopener" href="http://doc.bmob.cn/data/android/develop_doc/#2">Bmob用户系统</a></p>
<ol>
<li>创建表对应的bean类。User表需要继承自BmobUser，其中已封装用户名，密码等属性，以及登录，注册等方法。</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyUser</span> <span class="keyword">extends</span> <span class="title">BmobUser</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String stuno;</span><br><span class="line">    <span class="keyword">private</span> String sex;</span><br><span class="line">    <span class="keyword">private</span> String yuan;</span><br><span class="line">    <span class="keyword">private</span> String clazz;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 自行实现get set方法...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>登录，BmobUser中封装了多种登录方法，我们这里采用账号密码登录的方式。</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 手机号登录</span></span><br><span class="line">BmobUser.loginByAccount(username, password, <span class="keyword">new</span> LogInListener&lt;MyUser&gt;() &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">done</span><span class="params">(MyUser user, BmobException e)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (user != <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="comment">// 登录成功</span></span><br><span class="line">            onLoginSuccess();</span><br><span class="line">            progressDialog.dismiss();</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">// 登录失败</span></span><br><span class="line">            onLoginFailed();</span><br><span class="line">            progressDialog.dismiss();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>注册。Bmob中也封装了很多注册方法。账号密码注册比较简单。当然也可以做成用验证码注册的，不过需要提前充值短信条数。</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">final</span> User user = <span class="keyword">new</span> User();</span><br><span class="line">user.setUsername(<span class="string">&quot;username&quot;</span>);</span><br><span class="line">user.setPassword(<span class="string">&quot;password&quot;</span>);</span><br><span class="line">user.signUp(<span class="keyword">new</span> SaveListener&lt;User&gt;() &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">done</span><span class="params">(User user, BmobException e)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (e == <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="comment">// 注册成功</span></span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">// 注册失败</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<ol start="4">
<li>获取当前登录的用户以及用户属性。</li>
</ol>
<blockquote>
<p>获取缓存的用户信息，缓存的有效期为1年。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (BmobUser.isLogin()) &#123;</span><br><span class="line">    <span class="comment">// 获取缓存用户对象</span></span><br><span class="line">    MyUser user = BmobUser.getCurrentUser(MyUser.class);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="5">
<li>退出登录</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//清除缓存用户对象，退出登录</span></span><br><span class="line">BmobUser.logOut();</span><br></pre></td></tr></table></figure>

<h2 id="补充优化"><a href="#补充优化" class="headerlink" title="补充优化"></a>补充优化</h2><ul>
<li>凡是输入框都应该根据实际情况做一些限制，比如输入类型，输入长度，以此来减少用户恶意操作。</li>
<li>登录注册页面来回跳转后，应该对返回键做相应处理，防止返回时再次跳转。</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 重写返回键的返回方法</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onBackPressed</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="comment">// Disable going back to the ReviewTestActivity</span></span><br><span class="line">    moveTaskToBack(<span class="keyword">true</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>页面跳转时，可以设置相应的跳转动画，以此优化用户体验。</li>
</ul>
<p>java代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Intent intent = <span class="keyword">new</span> Intent(getApplicationContext(), SignupActivity.class);</span><br><span class="line">startActivityForResult(intent, REQUEST_SIGNUP);</span><br><span class="line">finish();</span><br><span class="line"><span class="comment">//动画效果</span></span><br><span class="line">overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);</span><br></pre></td></tr></table></figure>

<p>动画<br>push_left_in.xml</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">set</span> <span class="attr">xmlns:android</span>=<span class="string">&quot;http://schemas.android.com/apk/res/android&quot;</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">translate</span></span></span><br><span class="line"><span class="tag">		<span class="attr">android:duration</span>=<span class="string">&quot;500&quot;</span></span></span><br><span class="line"><span class="tag">		<span class="attr">android:fromXDelta</span>=<span class="string">&quot;100%p&quot;</span></span></span><br><span class="line"><span class="tag">		<span class="attr">android:toXDelta</span>=<span class="string">&quot;0&quot;</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">set</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>push_left_out.xml</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">set</span> <span class="attr">xmlns:android</span>=<span class="string">&quot;http://schemas.android.com/apk/res/android&quot;</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">translate</span></span></span><br><span class="line"><span class="tag">		<span class="attr">android:duration</span>=<span class="string">&quot;500&quot;</span></span></span><br><span class="line"><span class="tag">		<span class="attr">android:fromXDelta</span>=<span class="string">&quot;0&quot;</span></span></span><br><span class="line"><span class="tag">		<span class="attr">android:toXDelta</span>=<span class="string">&quot;-100%p&quot;</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">set</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>如果本文对你有所帮助，还望可以随手赏一个点赞哈 ~ ~</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Android/" rel="tag"># Android</a>
              <a href="/tags/%E7%A7%91%E5%B8%88%E6%9C%89%E7%BA%A6/" rel="tag"># 科师有约</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2018/04/03/%E5%AE%89%E5%8D%93%E5%9F%BA%E7%A1%80%E6%9D%83%E9%99%90%E6%80%BB%E7%BB%93/" rel="prev" title="安卓基础权限总结">
      <i class="fa fa-chevron-left"></i> 安卓基础权限总结
    </a></div>
      <div class="post-nav-item">
    <a href="/2018/04/12/%E6%89%8B%E6%8A%8A%E6%89%8B%E5%B8%A6%E4%BD%A0%E6%92%B8%E4%B8%80%E4%B8%AA%E6%A0%A1%E5%9B%ADAPP%EF%BC%88%E4%B8%83%EF%BC%89%EF%BC%9A%E6%A0%A1%E5%9B%AD%E6%96%87%E5%8C%96%E6%A8%A1%E5%9D%97%EF%BC%88%E7%A4%BE%E5%9B%A2%E6%B4%BB%E5%8A%A8&%E8%A1%A8%E7%99%BD%E5%A2%99&%E5%9B%BE%E8%AF%B4%E6%A0%A1%E5%9B%AD%EF%BC%89/" rel="next" title="手把手带你撸一个校园APP（七）：校园文化模块（社团活动&表白墙&图说校园）">
      手把手带你撸一个校园APP（七）：校园文化模块（社团活动&表白墙&图说校园） <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%89%8D%E8%A8%80"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%90%8E%E5%8F%B0"><span class="nav-number">2.</span> <span class="nav-text">后台</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E8%AE%BE%E8%AE%A1"><span class="nav-number">3.</span> <span class="nav-text">数据库设计</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E5%8D%93%E7%AB%AF%E7%A8%8B%E5%BA%8F"><span class="nav-number">4.</span> <span class="nav-text">安卓端程序</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B8%83%E5%B1%80"><span class="nav-number">5.</span> <span class="nav-text">布局</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#TextInputLayout"><span class="nav-number">5.1.</span> <span class="nav-text">TextInputLayout</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#java-%E9%80%BB%E8%BE%91"><span class="nav-number">6.</span> <span class="nav-text">java 逻辑</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A1%A5%E5%85%85%E4%BC%98%E5%8C%96"><span class="nav-number">7.</span> <span class="nav-text">补充优化</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">vchao</p>
  <div class="site-description" itemprop="description">怀揣好奇，梦想改变世界的菜鸟极客</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">46</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">27</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">冀ICP备 17022751号-1 </a>
      <img src="https://beian.miit.gov.cn" style="display: inline-block;">
  </div>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">vchao</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
